package by.ostrovsky.webhousingsystem.controller.account;

import java.util.LinkedList;
import java.util.List;

import org.apache.log4j.Logger;

import by.ostrovsky.webhousingsystem.controller.IUserController;
import by.ostrovsky.webhousingsystem.dao.DAOFactory;
import by.ostrovsky.webhousingsystem.dao.implementation.idao.IOperateDAO;
import by.ostrovsky.webhousingsystem.exception.CommonException;
import by.ostrovsky.webhousingsystem.exception.OperationErrorException;
import by.ostrovsky.webhousingsystem.hibernate.entity.Account;

public class RegistrationController implements IUserController<Account, Boolean>{
	private static Logger logger = Logger
			.getLogger(RegistrationController.class);

	@Override
	public Boolean registrate(Account account) throws OperationErrorException{
		try {
			DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.MySQL);
			IOperateDAO<List<Account>, Boolean> dao = factory.getAccountDAO();
			List<Account> list = new LinkedList<Account>();
			
			list.add(account);
			Boolean isOk = dao.create(list);
			if (isOk)
				return true;
		}catch (Exception e) {
			logger.error(e);
			throw new OperationErrorException();
		}
		return false;
	}

	@Override
	public Boolean send(Account object) throws CommonException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String login(Account object) throws CommonException {
		// TODO Auto-generated method stub
		return null;
	}
}
